package com.example.spinning.service;

import com.example.spinning.bean.MaterialQuality;
import com.example.spinning.mapper.MaterialQualityMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.sql.Date;
import java.util.List;

@Service
@Transactional
public class MaterialQualityService {
    @Autowired
    MaterialQualityMapper materialQualityMapper;


    //增加操作
    public int addNewMaterialQuality(MaterialQuality materialQuality) {

        return materialQualityMapper.addNewMaterialQuality(materialQuality);
    }

    //删除操作
    public boolean deleteMaterialQualityById(Long[] ids) {
        int result = materialQualityMapper.deleteMaterialQualityById(ids);
        return result == ids.length;
    }


    //查询并分页
    public PageInfo<MaterialQuality> findPage(Integer page, Integer size,String batch_no,String name,Date date,String origin,String colour) {

        MaterialQuality materialQuality = new MaterialQuality();
        materialQuality.setBatch_no(batch_no);
        materialQuality.setName(name);
        materialQuality.setDate(date);
        materialQuality.setOrigin(origin);
        materialQuality.setColour(colour);

       PageHelper.startPage(page,size);
        List<MaterialQuality> list = materialQualityMapper.select(materialQuality);
        PageInfo<MaterialQuality> pageInfo = new PageInfo<>(list);

        return pageInfo;

        /**
         * //根据名字模糊查询
         *     public List<OutStock> getOutStockByName(Integer page, Integer count,String product_name){
         *         int start = (page - 1) * count;
         *         return outStockMapper.getOutStockByName(start,count,product_name);
         *     }
         */
    }
    //动态修改
    public int updateCategoryById(MaterialQuality materialQuality){

         int result = materialQualityMapper.updateByPrimaryKeySelective(materialQuality);

        return result;
    }



}
